package com.kangye.learnteacher.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kangye.learnteacher.entity.Classes;
import com.kangye.learnteacher.entity.Grade;
import com.kangye.learnteacher.mapper.GradeMapper;
import com.kangye.learnteacher.service.GradeService;
import com.kangye.learnteacher.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GradeServiceImpl implements GradeService {


    @Autowired
    private GradeMapper gradeMapper;
    @Autowired
    private ViewJsonObject viewJsonObject;

    @Override
    public ViewJsonObject<Grade> getGrade(Integer page, Integer limit,String gradeName) {
        PageHelper.startPage(page,limit);
        List<Grade> list = gradeMapper.getGrade(page,limit,gradeName);
        PageInfo<Grade> pageInfo =  new PageInfo<>(list);

        viewJsonObject.setData(pageInfo.getList());
        viewJsonObject.setCount(pageInfo.getTotal());
        viewJsonObject.setCode(0);
        viewJsonObject.setMsg("");
        return viewJsonObject;
    }

    @Override
    public boolean upGrade(Grade grade) {
        return this.gradeMapper.upGrade(grade)>0;
    }
}

